
package base.core.api;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import org.springframework.cloud.openfeign.SpringQueryMap;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;

/**
 * @Description 基础的增删改查接口
 * @CreatDate 2021/12/16 14:55
 */
public interface BaseFeign<T> {

    @GetMapping("one")
    @Operation(summary = "#.获取单条数据")
    Result<T> getOne(@SpringQueryMap T condition);

    @GetMapping("list")
    @Operation(summary = "#.获取多条数据")
    Result<List<T>> getList(@SpringQueryMap T condition);

    @GetMapping("page")
    @Operation(summary = "#.获取分页数据")
    Result<Page<T>> getPage(
            @Parameter(description = "单页数据量") @RequestParam(value = "size", required = false) Long size,
            @Parameter(description = "当前页码") @RequestParam(value = "current", required = false) Long current,
            @Parameter(description = "是否Count总数") @RequestParam(value = "searchCount", required = false) Boolean searchCount,
            @Parameter(description = "排序(createTime desc, id)") @RequestParam(value = "orders", required = false) String[] orders,
            @Parameter(description = "查询条件") @SpringQueryMap T condition);

    @GetMapping("/{id}")
    @Operation(summary = "#.获取单条数据ByID")
    Result<T> getById(@PathVariable("id") Serializable id);

    @PostMapping
    @Operation(summary = "#.新增单条数据")
    Result<T> create(@RequestBody T record);

    @PutMapping
    @Operation(summary = "#.修改单条数据")
    Result<T> update(@RequestBody T record);

    @DeleteMapping("/{id}")
    @Operation(summary = "#.删除单条数据")
    Result deleteById(@PathVariable("id") Serializable id);

    @PutMapping("saveOrUpdate")
    @Operation(summary = "#.修改或新增单条数据")
    Result<T> saveOrUpdate(@RequestBody T record);

    @PutMapping("saveOrUpdateBatch")
    @Operation(summary = "#.修改或新增多条数据")
    Result saveOrUpdateBatch(@RequestBody Collection<T> records);

    @PutMapping("updateBatchById")
    @Operation(summary = "#.修改多条数据ByID")
    Result updateBatchById(@RequestBody List<T> records);

    @PutMapping("updateBatch")
    @Operation(summary = "#.修改多条数据")
    Result updateBatch(@RequestBody T record, @SpringQueryMap T condition);

    @GetMapping("ping")
    @Operation(summary = "#.Ping 接口连通性")
    Result ping();
}
